package com.cloud.pole.user.biz.collection;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Options;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.mapper.collection.UserCollectionMapper;
import com.cloud.pole.user.model.entity.collection.UserCollection;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
@Transactional(rollbackFor = Exception.class)
public class UserCollectionBiz extends BaseBiz<UserCollectionMapper, UserCollection> {
	
	@Autowired
	UserCollectionMapper userCollectionMapper;
	
	/**
	 * 清除某些前缀key缓存
	 */
	@Override
    @CacheClear(pre="userCollection{1.userId}user{1.objectTypeId}type")
    public void insertSelective(UserCollection entity) {
		super.insertSelective(entity);
    }
	
	/**
	 * 清除某些前缀key缓存
	 */
    @CacheClear(pre="userCollection{1.userId}user{1.objectTypeId}type")
	public void deleteById(UserCollection entity) {
		super.delete(entity);
	}	
	
    @Cache(key="userCollection{1}user{2}type{3}object")
    //@Cache(key="userCollection{1}#{2}#{3}#")
    public UserCollection getUserCollectionByObjectId(Long userId, Integer objectTypeId, String objectId){
    	UserCollection msg = new UserCollection();
    	msg.setUserId(userId);
    	msg.setObjectTypeId(objectTypeId);
    	msg.setObjectId(objectId);
        return super.selectOne(msg);
    }
    
    @Cache(key="userCollection{1}user{2}type")
    public List<UserCollection> getUserCollectionList(Long userId, Integer objectTypeId){
    	 Example example = new Example(UserCollection.class);
		 Criteria criteria = example.createCriteria();
    	 example.setOrderByClause("collection_id desc");
    	 criteria.andEqualTo("objectTypeId", objectTypeId);
    	 criteria.andEqualTo("userId", userId);
         return super.selectByExample(example);
    }
}
